package com.iRomantic.domain.entity;

import java.sql.Timestamp;
import java.util.UUID;

import com.iRomantic.config.Constant;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.upload.UploadFile;

public class Version extends Model<Version> {
	
	private static final long serialVersionUID = -4007644785874930130L;
	
	public static final Version DAO = new Version();
	
	/**
	 * 安卓
	 */
	public static final int TYPE_ANDROID = 0;
	
	/**
	 * IOS
	 */
	public static final int TYPE_IOS = 1;
	
	/**
	 * WP
	 */
	public static final int TYPE_WP = 2;
	
	/**
	 * 保存
	 */
	public boolean save(){
		this.set("id", UUID.randomUUID().toString());
		this.set("createTime", new Timestamp(System.currentTimeMillis()));
		return super.save();
	}
	
	/**
	 * 根据类型获取最新版本
	 * @return
	 */
	public Version findLastVrsionByType(int type){
		return this.findFirst("select * from t_version where type=? order by createTime desc ",type);
	}
	
	/**
	 * 根据类型修改isNew
	 * @param isNew
	 * @param type
	 * @return
	 */
	public int updateStatusAllByType(int isNew, int type){
		return Db.update("update t_version set isNew=? where type=? ", isNew,type);
	}
	
	public void setProjectPath(Version version){
		if(null!=version.getStr("url")){
			version.set("url", Constant.OSS_PATH+Constant.VERSION_PACKAGE +version.getStr("url"));
		}
	}
	
}
